function [F, T, T_J] = Wald_GMM(beta, COVAR, k)

%This file conducts the F and P Wald tests for the IVLogit GMM model


%F-test statistic
F(1,1) = (beta'*inv(COVAR)*beta)/(2*k);

F(2,1) = (beta(1:k)'*inv(COVAR(1:k,1:k))*beta(1:k))/k;

F(3,1) = (beta(k+1:2*k)'*inv(COVAR(k+1:2*k,k+1:2*k))*beta(k+1:2*k))/k;


%Wald test statistics
T = beta./((diag(COVAR)).^0.5); %t-stat to be reporteds

%Wald Statistic for joint significance of all t betas for the same independent variable

for j=1:k
    T_J(j)=([beta(j); beta(k+j)]'...
        *inv([COVAR(j,j) COVAR(j,k+j); COVAR(k+j,j) COVAR(k+j,k+j)])...
        *[beta(j); beta(k+j)])/2;
end
T_J=T_J';